﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:ViewModels="clr-namespace:ScrumSprintMonitor.Modules.WorkItemMonitor.ViewModels">

	<Style x:Key="InfoLabel" TargetType="{x:Type TextBlock}">
		<Setter Property="FontSize" Value="64" />
		<Setter Property="FontWeight" Value="Light" />
		<Setter Property="Opacity" Value="0.7" />
		<Setter Property="VerticalAlignment" Value="Bottom" />
		<Setter Property="HorizontalAlignment" Value="Stretch" />
		<Setter Property="Foreground" Value="White" />
	</Style>

	<Style x:Key="NumericValueLabel" TargetType="{x:Type TextBlock}">
		<Setter Property="FontStyle" Value="Italic" />
		<Setter Property="FontSize" Value="64" />
		<Setter Property="VerticalAlignment" Value="Bottom" />
		<Setter Property="HorizontalAlignment" Value="Right" />
		<Setter Property="Foreground" Value="White" />
	</Style>

	<DataTemplate x:Key="HoursAvailableDataTemplate">
		<TextBlock>
			<TextBlock.Style>
				<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource NumericValueLabel}">
					<Setter Property="Text" Value="{Binding Path=AvailableHours, StringFormat='{}{0:N0} hours'}" />

					<Style.Triggers>
						<DataTrigger Binding="{Binding TimeIncludesFreeBusyInformation}" Value="False">
							<Setter Property="Text" Value="{Binding Path=AvailableHours, StringFormat='≤ {0:N0} hours'}" />
						</DataTrigger>
					</Style.Triggers>
				</Style>
			</TextBlock.Style>
		</TextBlock>
	</DataTemplate>

	<DataTemplate DataType="{x:Type ViewModels:SprintStatsViewModel}">
		<StackPanel>
			<Grid HorizontalAlignment="Center">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" SharedSizeGroup="ItemNameColumn" />
					<ColumnDefinition Width="Auto" SharedSizeGroup="ItemValueColumn" />
				</Grid.ColumnDefinitions>

				<Grid.Style>
					<Style TargetType="{x:Type Grid}">
						<Setter Property="Visibility" Value="Visible" />

						<Style.Triggers>
							<DataTrigger Binding="{Binding ShowAverageResolutionTime}" Value="False">
								<Setter Property="Visibility" Value="Collapsed" />
							</DataTrigger>
						</Style.Triggers>
					</Style>
				</Grid.Style>

				<TextBlock Grid.Column="0" Text="Average resolution time:" Style="{StaticResource InfoLabel}" />
				<TextBlock Grid.Column="1">
					<TextBlock.Style>
						<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource NumericValueLabel}">
							<Setter Property="Text" Value="{Binding AverageResolutionTime, StringFormat='{}{0:N0} hours'}" />

							<Style.Triggers>
								<DataTrigger Binding="{Binding AverageResolutionTime}" Value="NaN">
									<Setter Property="Text" Value="N/A" />
								</DataTrigger>
							</Style.Triggers>
						</Style>
					</TextBlock.Style>
				</TextBlock>
			</Grid>

			<Grid HorizontalAlignment="Center">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" SharedSizeGroup="ItemNameColumn" />
					<ColumnDefinition Width="Auto" SharedSizeGroup="ItemValueColumn" />
				</Grid.ColumnDefinitions>

				<TextBlock Grid.Column="0" Text="Time available:" Style="{StaticResource InfoLabel}" />
				<ContentControl Grid.Column="1" Content="{Binding}" ContentTemplate="{StaticResource HoursAvailableDataTemplate}" HorizontalAlignment="Right" Focusable="False" />
			</Grid>

			<Grid HorizontalAlignment="Center">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" SharedSizeGroup="ItemNameColumn" />
					<ColumnDefinition Width="Auto" SharedSizeGroup="ItemValueColumn" />
				</Grid.ColumnDefinitions>

				<Grid.Resources>
					<Storyboard x:Key="FadeInOver2Seconds">
						<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0.7" Duration="00:00:02" />
					</Storyboard>
					<Storyboard x:Key="FadeOutOver2Seconds">
						<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0" Duration="00:00:02" />
					</Storyboard>
				</Grid.Resources>

				<Grid.Style>
					<Style TargetType="{x:Type Grid}">
						<Setter Property="Visibility" Value="Collapsed" />
						<Setter Property="Opacity" Value="0" />

						<Style.Triggers>
							<!-- Animate the opacity and visibility -->
							<DataTrigger Binding="{Binding ShowAheadOfScheduleBy}" Value="True">
								<DataTrigger.ExitActions>
									<BeginStoryboard>
										<Storyboard>
											<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0" Duration="00:00:05" />
											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility">
												<DiscreteObjectKeyFrame KeyTime="00:00:05" Value="{x:Static Visibility.Collapsed}" />
											</ObjectAnimationUsingKeyFrames>
										</Storyboard>
									</BeginStoryboard>
								</DataTrigger.ExitActions>

								<DataTrigger.EnterActions>
									<BeginStoryboard>
										<Storyboard>
											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility">
												<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}" />
											</ObjectAnimationUsingKeyFrames>
											<DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="00:00:05" />
										</Storyboard>
									</BeginStoryboard>
								</DataTrigger.EnterActions>
							</DataTrigger>
						</Style.Triggers>
					</Style>
				</Grid.Style>

				<TextBlock Grid.Column="0" Text="Ahead of schedule by:">
					<TextBlock.Style>
						<Style BasedOn="{StaticResource InfoLabel}" TargetType="{x:Type TextBlock}">
							<Setter Property="Opacity" Value="0" />

							<Style.Triggers>
								<DataTrigger Binding="{Binding IsAheadOfSchedule}" Value="True">
									<DataTrigger.ExitActions>
										<BeginStoryboard Storyboard="{StaticResource FadeOutOver2Seconds}" />
									</DataTrigger.ExitActions>

									<DataTrigger.EnterActions>
										<BeginStoryboard Storyboard="{StaticResource FadeInOver2Seconds}" />
									</DataTrigger.EnterActions>
								</DataTrigger>
							</Style.Triggers>
						</Style>
					</TextBlock.Style>
				</TextBlock>
				<TextBlock Grid.Column="0" Text="Behind schedule by:">
					<TextBlock.Style>
						<Style BasedOn="{StaticResource InfoLabel}" TargetType="{x:Type TextBlock}">
							<Setter Property="Opacity" Value="0.7" />

							<Style.Triggers>
								<DataTrigger Binding="{Binding IsAheadOfSchedule}" Value="True">
									<DataTrigger.ExitActions>
										<BeginStoryboard Storyboard="{StaticResource FadeInOver2Seconds}" />
									</DataTrigger.ExitActions>

									<DataTrigger.EnterActions>
										<BeginStoryboard Storyboard="{StaticResource FadeOutOver2Seconds}" />
									</DataTrigger.EnterActions>
								</DataTrigger>
							</Style.Triggers>
						</Style>
					</TextBlock.Style>
				</TextBlock>
				<TextBlock Grid.Column="1" Text="{Binding DifferenceToSchedule, StringFormat=' {0:N0} hours'}" Foreground="{Binding AheadOfScheduleForegroundBrush}" Style="{StaticResource NumericValueLabel}" />
			</Grid>
		</StackPanel>
	</DataTemplate>
</ResourceDictionary>